//
//  LBCDetailNewViewController.m
//  Moment
//
//  Created by dllo on 15/11/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LBCDetailNewViewController.h"

@interface LBCDetailNewViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain)UITableView *DetailNewTableView;
@property (nonatomic, retain)NSMutableArray *detailNewArray;
@property (nonatomic, retain)NSString *contentId;

@end

@implementation LBCDetailNewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
#pragma mark- 创建tableView
    self.DetailNewTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _DetailNewTableView.backgroundColor = [UIColor whiteColor];
    _DetailNewTableView.delegate = self;
    _DetailNewTableView.dataSource = self;
    [self.view addSubview:_DetailNewTableView];
    [_DetailNewTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.mas_equalTo(@0);
        make.bottom.mas_equalTo(@-110);
        
    }];
    _DetailNewTableView.rowHeight = SCREEN_HEIGHT / 3.7;
#pragma mark 注册cell
    [_DetailNewTableView registerClass:[LBCDetailNewCell class] forCellReuseIdentifier:@"detailNewCell"];
    // 取消多余的线
    _DetailNewTableView.tableFooterView = [UIView new];
#pragma mark- 请求数据
    _detailNewArray = [NSMutableArray array];
    
}

-(void)setReadList:(LBCReadList *)readList{
    _readList = readList;
    [self getAFNetWorkingData];
}
#pragma mark- 数据解析
- (void)getAFNetWorkingData{
    NSString *urlStr = @"http://api2.pianke.me/read/columns_detail";
    NSString *para = [NSString stringWithFormat:@"auth=&client=1&deviceid=0F79DA7D-8DF2-416D-B3C3-7BD488A50BDD&limit=10&sort=addtime&start=0&typeid=%ld&version=3.0.6", self.readList.type];
    NSLog(@"===========%ld", _readList.type);
    [AFNetworkTool postUrl:urlStr body:para result:HXJSON requestStyle:HXRequestString headerFile:nil success:^(id result) {
        NSMutableDictionary *bigDic = [result objectForKey:@"data"];
        for (NSMutableDictionary *dic in [bigDic objectForKey:@"list"]) {
            LBCDetailList *detailList = [[LBCDetailList alloc] init];
            [detailList setValuesForKeysWithDictionary:dic];
            [_detailNewArray addObject:detailList];
        }
        [_DetailNewTableView reloadData];
    } failure:^(NSError *error) {
        
        
    }];
}


#pragma mark- 设置行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _detailNewArray.count;
}
#pragma mark- 设置cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *detailNewIdntifier = @"detailNewCell";
    LBCDetailNewCell *detailNewCell = [tableView dequeueReusableCellWithIdentifier:detailNewIdntifier];
    // 取消点击cell的效果
    detailNewCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    detailNewCell.detailListCell = _detailNewArray[indexPath.row];
    
    return detailNewCell;
}
#pragma mark- 点击cell触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LBCDetailViewController *detailVC = [[LBCDetailViewController alloc] init];
    LBCDetailList *detailList = [self.detailNewArray objectAtIndex:indexPath.row];
    detailVC.contentId = detailList.contentId;
    detailVC.titleStr = detailList.title;
    [self.navigationController pushViewController:detailVC animated:YES];
   
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
